<template>
  <ContentWrap>
    <!-- 搜索工作栏 -->
    <el-form
      ref="formRef"
      :model="formData"
      :rules="formRules"
      label-position="left"
      label-width="100px"
      v-loading="formLoading"
    >
    <div>
      <el-form-item label="模型名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入"
          clearable
          @keyup.enter="handleQuery"
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item label="审核状态" prop="status">
        <el-select
          v-model="queryParams.status"
          placeholder="请选择状态"
          clearable
          class="!w-240px"
        >
          <el-option
            v-for="dict in getIntDictOptions(DICT_TYPE.MODEL_EXEC_STATUS)"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
    </div>
      <el-form-item>
        <el-button @click="resetQuery" plain type="primary">重置</el-button>
        <el-button @click="handleQuery" type="primary">查询</el-button>
      </el-form-item>
    </el-form>
  </ContentWrap>

  <!-- 列表 -->
  <ContentWrap>
    <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true" :header-cell-style="{ 'background': '#CCEBE7' }" :align="'center'">
      <!-- <el-table-column label="ID" align="center" prop="id" /> -->
      <el-table-column label="序号" type="index" width="60px" align="center" />
      <el-table-column label="模型名称" align="center" prop="name" />
      <el-table-column label="模型能力" align="center" prop="largeModelIds" />
      <el-table-column label="镜像名称" align="center" prop="name" />
      <el-table-column label="信息模态" align="center" prop="name" />
      <el-table-column label="厂商名称" align="center" prop="name" />
      <el-table-column
        label="申请时间"
        align="center"
        prop="createTime"
        :formatter="dateFormatter"
        width="180px"
      />
      <el-table-column label="审核状态" align="center" prop="status">
        <template #default="scope">
          <dict-tag :type="DICT_TYPE.MODEL_EXEC_STATUS" :value="scope.row.status" />
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center">
        <template #default="scope">
          <el-button
            link
            :type="scope.row.status === 0 ? 'primary' : ''"
            @click="openForm(scope.row.id)"
            v-hasPermi="['multiModel:evaluation-task:update']"
            :disabled="scope.row.status !== 0"
          >
            审核
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <Pagination
      :total="total"
      v-model:page="queryParams.pageNo"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />
  </ContentWrap>
  <!-- 弹窗: 申请表格审核 -->
  <ApplicationForm ref="formRef" @success="getList" />
</template>

<script setup lang="ts">
import { getIntDictOptions, DICT_TYPE, getDictOptions } from '@/utils/dict'
import { dateFormatter } from '@/utils/formatTime'
import { EvaluationTaskApi, EvaluationTaskVO } from '@/api/multiModel/evaluationtask'

/** 模型评价 列表 */
defineOptions({ name: 'EvaluationReview' })

const message = useMessage() // 消息弹窗
const { t } = useI18n() // 国际化

const loading = ref(true) // 列表的加载中
const list = ref<EvaluationTaskVO[]>([]) // 列表的数据
const total = ref(0) // 列表的总页数
const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  name: undefined,
  status: undefined,
})
const queryFormRef = ref() // 搜索的表单
/** 查询列表 */
const getList = async () => {
  loading.value = true
  try {
    const data = await EvaluationTaskApi.getEvaluationTaskPage(queryParams)
    list.value = data.list
    total.value = data.total
  } finally {
    loading.value = false
  }
}

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.pageNo = 1
  getList()
}
/** 评分规则弹窗 */
const judgingRef = ref()
const openJudging = (type: string, id?: number) => {
  judgingRef.value.open(type, id)
}
/** 重置按钮操作 */
const resetQuery = () => {
  queryFormRef.value.resetFields()
  handleQuery()
}

/** 创建 */
const formRef = ref()
const openForm = (id: number) => {
  formRef.value.open(id)
}
// 推理
const handleStatus = (id:number, status: number) => {
  console.log(id, status, 'handleStatus----')
}
/** 详情 */
const router = useRouter() // 路由
const goDetail = (id: number) => {
  router.push({
    path: '/task/detail',
    query: {
      id
    }
  })
}
// const dictData = ref<DictDataType>()
// const getDictObj = (dictType: string, value: string) => {
//   const dictOptions = getDictOptions(dictType)
//   dictOptions.forEach((dict: DictDataType) => {
//     if (dict.value === value) {
//       if (dict.colorType + '' === 'primary' || dict.colorType + '' === 'default') {
//         dict.colorType = ''
//       }
//       dictData.value = dict
//     }
//   })
// }
const evaluationTypeObj = ref({})
const getTypeObj = () => {
  const dictOptions = getDictOptions(DICT_TYPE.MODEL_EVALUATE_TYPE)
  dictOptions.forEach(dict => {
    evaluationTypeObj.value[dict.value] = dict.label
  })
}


/** 初始化 **/
onMounted(() => {
  getList()
  getTypeObj()
})
</script>